#include "q_shared.h"

__declspec(dllexport) int Q_stricmpn (const char *s1, const char *s2, int n) {
	int		c1, c2;

	// bk001129 - moved in 1.17 fix not in id codebase
        if ( s1 == NULL ) {
           if ( s2 == NULL )
             return 0;
           else
             return -1;
        }
        else if ( s2==NULL )
          return 1;


	
	do {
		c1 = *s1++;
		c2 = *s2++;

		if (!n--) {
			return 0;		// strings are equal until end point
		}
		
		if (c1 != c2) {
			if (c1 >= 'a' && c1 <= 'z') {
				c1 -= ('a' - 'A');
			}
			if (c2 >= 'a' && c2 <= 'z') {
				c2 -= ('a' - 'A');
			}
			if (c1 != c2) {
				return c1 < c2 ? -1 : 1;
			}
		}
	} while (c1);
	
	return 0;		// strings are equal
}

__declspec(dllexport) int Q_strncmp (const char *s1, const char *s2, int n) {
	int		c1, c2;
	
	do {
		c1 = *s1++;
		c2 = *s2++;

		if (!n--) {
			return 0;		// strings are equal until end point
		}
		
		if (c1 != c2) {
			return c1 < c2 ? -1 : 1;
		}
	} while (c1);
	
	return 0;		// strings are equal
}


//RACC - scans for s1 at the start of s2
//1 = s1 is at beginning of s2 but they are not exactly the same
//0 = s1 = s2
//-1 = didn't find s1 at the start of s2
__declspec(dllexport) int Q_stricmp (const char *s1, const char *s2) {
	return (s1 && s2) ? Q_stricmpn (s1, s2, 99999) : -1;
}

int Q_stricmp_safe(const char *s1, const char *s2)
{
	if(!s1 && !s2)
	{
		return 0;
	}
	if(!s1 && s2)
	{
		return -1;
	}
	if(s1 && !s2)
	{
		return 1;
	}
	return Q_stricmp(s1, s2);
}

// Vector Math functions
__declspec(dllexport) __inline void __cdecl VectorSet2(vec3_t *vec, float value)
{
	(*vec)[0] = value;
	(*vec)[1] = value;
	(*vec)[2] = value;
}

__declspec(dllexport) void VectorSet(vec3_t *vec, float val1, float val2, float val3)
{
	(*vec)[0] = val1;
	(*vec)[1] = val2;
	(*vec)[2] = val3;
}